Skip to content

Clean up code for drawing overlays to accept sRGB hex codes instead of Color structs#3839

Merged
Keavon merged 2 commits intomasterfrom
overlays-color-cleanup
Feb 27, 2026
Merged

Clean up code for drawing overlays to accept sRGB hex codes instead of Color structs#3839
Keavon merged 2 commits intomasterfrom
overlays-color-cleanup

Conversation

@Keavon
Copy link
Copy Markdown
Member

@Keavon Keavon commented Feb 27, 2026

No description provided.

@gemini-code-assist
Copy link
Copy Markdown
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request refactors the color handling mechanism for drawing overlays throughout the editor. The primary goal is to streamline the process by transitioning from using graphene_std::Color structs to directly employing sRGB hex code strings. This change simplifies the API for overlay drawing, eliminates unnecessary color conversions at the point of use, and improves overall consistency in how overlay colors are defined and applied. The update impacts various tools and grid display logic, ensuring a more direct and efficient approach to rendering visual aids.

Highlights

  • Standardized Overlay Color Representation: Overlay drawing functions across the editor now consistently accept sRGB hex code strings (e.g., '#RRGGBBAA') instead of graphene_std::Color structs, simplifying color handling and ensuring consistent visual representation.
  • Expanded Overlay Color Constants: New sRGB hex code constants have been introduced in editor/src/consts.rs for various overlay colors with different opacity levels (e.g., COLOR_OVERLAY_BLUE_25, COLOR_OVERLAY_WHITE_05), reducing redundant color calculations.
  • Refactored Grid Snapping Color: The grid_color field within the GridSnapping struct has been updated from a Color struct to a String to directly store and manage the sRGB hex code for grid display colors.
  • Simplified Color Utility Functions: Several color conversion utility functions (from_rgb_hex_for_overlays, from_rgba_str, from_rgb_str) were removed from node-graph/libraries/no-std-types/src/color/color_types.rs, and the from_hex_str function was consolidated to handle all hex string formats.
Changelog
  • editor/src/consts.rs
    • Added new sRGB hex code constants for overlay colors with varying opacities, including COLOR_OVERLAY_BLUE_25, COLOR_OVERLAY_BLUE_05, COLOR_OVERLAY_GREEN_25, COLOR_OVERLAY_RED_25, and COLOR_OVERLAY_WHITE_05.
  • editor/src/messages/portfolio/document/overlays/grid_overlays.rs
    • Updated grid color retrieval to directly use the color field as a string from document.snapping_state.grid.
    • Modified overlay_context.line and overlay_context.pixel calls to pass the grid_color string directly, removing the need for string concatenation and & referencing.
  • editor/src/messages/portfolio/document/overlays/utility_types_native.rs
    • Removed the import of graphene_std::Color as it is no longer directly used for overlay drawing.
    • Updated the fill_path_pattern function signature to accept &str for color instead of &Color.
    • Simplified color generation for draw_scale and draw_compass_rose by directly using predefined sRGB hex constants instead of runtime Color conversions.
  • editor/src/messages/portfolio/document/overlays/utility_types_web.rs
    • Removed the import of graphene_std::Color.
    • Simplified color generation for draw_scale and draw_compass_rose by using predefined sRGB hex constants.
    • Updated the fill_path_pattern function signature to accept &str for color and modified its internal logic to parse the hex string directly for pattern creation.
  • editor/src/messages/portfolio/document/utility_types/misc.rs
    • Removed the import of graphene_std::raster::Color.
    • Changed the grid_color field in the GridSnapping struct to color: String.
    • Updated the default initialization of grid_color to use COLOR_OVERLAY_GRAY.to_string().
  • editor/src/messages/tool/tool_messages/fill_tool.rs
    • Modified the fill_path_pattern call to format the preview_color into an sRGB hex string before passing it.
  • editor/src/messages/tool/tool_messages/gradient_tool.rs
    • Updated the color_to_hex helper function to use to_rgb_hex_srgb_from_gamma() for color conversion.
  • editor/src/messages/tool/tool_messages/path_tool.rs
    • Added imports for new color constants COLOR_OVERLAY_BLUE_05, COLOR_OVERLAY_GREEN_25, and COLOR_OVERLAY_RED_25.
    • Simplified color generation for drawing selection shapes and axis lines by directly using predefined sRGB hex constants.
  • editor/src/messages/tool/tool_messages/pen_tool.rs
    • Added import for the new color constant COLOR_OVERLAY_BLUE_05.
    • Simplified color generation for filling paths by directly using COLOR_OVERLAY_BLUE_05.
  • editor/src/messages/tool/tool_messages/select_tool.rs
    • Simplified color generation for hover overlays, axis lines, and selection boxes by directly using predefined sRGB hex constants.
  • editor/src/messages/tool/tool_messages/text_tool.rs
    • Updated import to use COLOR_OVERLAY_BLUE_05 instead of COLOR_OVERLAY_BLUE.
    • Simplified color generation for text tool overlays by directly using COLOR_OVERLAY_BLUE_05.
  • node-graph/libraries/no-std-types/src/color/color_types.rs
    • Simplified the from_rgba8_srgb function by removing an intermediate map_range closure.
    • Removed deprecated color parsing functions: from_rgb_hex_for_overlays, from_rgba_str, and from_rgb_str.
    • Refactored from_hex_str to handle both 6-character (RGB) and 8-character (RGBA) hex strings more robustly.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

2 issues found across 12 files

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/messages/portfolio/document/overlays/utility_types_native.rs">

<violation number="1" location="editor/src/messages/portfolio/document/overlays/utility_types_native.rs:1067">
P2: Duplicated hex parsing logic — extract a shared `parse_color_bytes(color: &str) -> [u8; 4]` helper and have both `parse_color` and `fill_path_pattern` call it. This avoids maintaining the same parsing in two places.</violation>
</file>

<file name="editor/src/messages/portfolio/document/utility_types/misc.rs">

<violation number="1" location="editor/src/messages/portfolio/document/utility_types/misc.rs:218">
P1: Missing `#[serde(alias = "grid_color")]` on the renamed `color` field. Existing serialized documents (including all 8 demo `.graphite` files) store this value as `grid_color`. Without the alias, deserialization will silently discard the old value and replace it with the default, losing the user's saved grid color setting. This file already uses `#[serde(alias = ...)]` for the same purpose on `GridType::Rectangular`.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

Comment thread editor/src/messages/portfolio/document/utility_types/misc.rs
Comment thread editor/src/messages/portfolio/document/overlays/utility_types_native.rs Outdated
Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a nice cleanup that simplifies color handling for overlays by using sRGB hex codes instead of Color structs. The changes generally make the code cleaner and more efficient.

However, I've identified a critical issue where the new hex string parsing logic can cause a panic with malformed input, potentially crashing the application. This unsafe logic is duplicated in two files. Additionally, there's a color correctness bug in the gradient tool where colors are not being properly gamma-corrected before display. I've provided detailed comments and suggestions for these issues.

Comment thread editor/src/messages/portfolio/document/overlays/utility_types_native.rs Outdated
Comment thread editor/src/messages/portfolio/document/overlays/utility_types_web.rs Outdated
Comment thread editor/src/messages/tool/tool_messages/gradient_tool.rs
@github-actions github-actions Bot temporarily deployed to graphite-dev (Preview) February 27, 2026 21:51 Inactive
Copy link
Copy Markdown
Contributor

@cubic-dev-ai cubic-dev-ai Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

1 issue found across 3 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="editor/src/messages/portfolio/document/overlays/utility_functions.rs">

<violation number="1" location="editor/src/messages/portfolio/document/overlays/utility_functions.rs:255">
P2: Byte-index string slicing (`&hex[0..2]`) can panic on non-ASCII input that happens to be exactly 6 or 8 UTF-8 bytes (e.g., `"你好"` is 6 bytes). Add an ASCII check before slicing to maintain the graceful fallback behavior.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@github-actions github-actions Bot temporarily deployed to graphite-dev (Preview) February 27, 2026 22:06 Inactive
@Keavon Keavon merged commit a8b5203 into master Feb 27, 2026
7 checks passed
@Keavon Keavon deleted the overlays-color-cleanup branch February 27, 2026 22:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant